//DEFINED
//OBSERVATION_VECTOR_SIZE, NUMBER_OF_OBSERVATIONS,NUMBER_OF_CENTROIDS

float calculateDistance(const __global float* _x1, const __global float* _x2)
	{
		float returned=0;
		for(int i=0;i<OBSERVATION_VECTOR_SIZE;i++,_x1++,_x2++)
		{
			float diff_=(*_x1)-(*_x2);
			returned+=diff_*diff_;
		}

		returned=sqrt(returned);
		return returned;
	}

__kernel void findClosestCentroid(__global float* _observations,
                             __global float* _currentCentroids,
                             __global unsigned int* _closestCentroid)
{
    uint observationI = get_global_id(0);

	if(observationI>=NUMBER_OF_OBSERVATIONS)return;

	__global float* pObservation_=(__global float*)_observations+(observationI*OBSERVATION_VECTOR_SIZE);
    
	float minDist_=MAXFLOAT;
	unsigned int minI_=0;
	__global float* pCentroid_=(__global float*)_currentCentroids;
	for(int centroidI=0;centroidI<NUMBER_OF_CENTROIDS;centroidI++,pCentroid_+=OBSERVATION_VECTOR_SIZE)
	{
		float currentDist_=calculateDistance(pObservation_,pCentroid_);
		if(currentDist_<minDist_)
		{
			minDist_=currentDist_;
			minI_=centroidI;
		}
	}
	_closestCentroid[observationI]=minI_;
}
